package haois.module.traffic.service;


import haois.module.traffic.dao.mapper.TrafficMapper;
import haois.module.traffic.daomain.Traffic;
import haois.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by haol on 2017/4/22.
 */
@Service
public class TrafficService {
    @Autowired
    private TrafficMapper trafficMapper;


    public void addRecord(Traffic traffic) {
        traffic.setCreateTime(DateUtil.getYMdHms());
        trafficMapper.updateAppCount(traffic.getAppId());
        trafficMapper.saveRecord(traffic);
    }

    public List<Traffic> getRecordByAppId(String appId) {
        return trafficMapper.getRecordByAppId(appId);
    }


    public List<Traffic> getRecord() {
        return trafficMapper.getAllRecord();
    }

    public Traffic getRecord(int id) {
        return trafficMapper.getRecordById(id);
    }

    public boolean checkIsIgnore(String ip, String appId) {
        List<Integer> igns = trafficMapper.getIgnIdByIpAndAppId(ip, appId);
        return igns != null && !igns.isEmpty();
    }

    public void addNeglect(String appId) {
        trafficMapper.addIgnCount(appId);
    }


    public void deleteRecord(String appId) {
        trafficMapper.deleteRecordByAppId(appId);
    }

    public void deleteRecord(String appId, String ip) {
        trafficMapper.deleteRecordByAppIdAndIp(appId, ip);
    }

    public void update(Traffic traffic) {
        trafficMapper.update(traffic);
    }


}
